/*
 * @Author: xinyang3
 * @Date: 2021-11-08 14:53
 * @Descripttion: awesome description
 * @LastEditors: xinyang3
 * @LastEditTime: 2021-11-22 10:23
 */
import 'babel-polyfill';
import Koa from 'koa';
import logger from 'koa-logger';
import jsonp from 'koa-jsonp';
// const bodyParser = require('koa-bodyparser');
import koaBody from 'koa-body';
import session from 'koa-session';
import CONFIg, { sessionKey } from './config/session-config.js';
import { hostname } from 'os';
import { getConfig } from './config/index.js';
import router from './routers/index.js';

const config = getConfig();
const app = new Koa();

app.keys = [sessionKey];
app.use(session(CONFIg, app));
app.use(logger());
app.use(jsonp());
app.use(
  koaBody({
    multipart: true,
    queryString: true,
    formidable: {
      maxFieldsSize: 10 * 1024 * 1024,
      multipart: true,
      multiples: true,
    },
  })
);
app.use(router.routes());
app.use(router.allowedMethods());

app.listen(config.port, () => {
  console.debug(
    `app is running at ${hostname} http://127.0.0.1:${config.port}/`
  );
});

export default app;
